package com.wd.tech.activity;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wd.tech.R;

import com.wd.tech.adaptert.MoreAdaptert;
import com.wd.tech.base.BaseActivity;
import com.wd.tech.base.BasePreantert;
import com.wd.tech.bean.MorvBean;
import com.wd.tech.preantenrt.Preantert;
import com.wd.tech.utils.NetUtils;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * 更多
 */
public class MoreActivity extends BaseActivity {

    private RecyclerView morv_rv;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_more;
    }

    @Override
    protected BasePreantert initPreantert() {
        return new Preantert(this);
    }

    @Override
    protected void initView() {
        morv_rv = findViewById(R.id.morv_rv);
    }

    @Override
    protected void initData() {
        NetUtils.getInstance().getApis().getMorvBean().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<MorvBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    //直接调取成功的方法
                    @Override
                    public void onNext(MorvBean morvBean) {
                        //获取集合数据
                        List<MorvBean.ResultBean> result = morvBean.getResult();
                        GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(), 2);
                        morv_rv.setLayoutManager(gridLayoutManager);
                        MoreAdaptert moreAdaptert = new MoreAdaptert(getApplicationContext(), result);
                        moreAdaptert.setOnClick(new MoreAdaptert.setOnClick() {
                            @Override
                            public void ck(int id) {

                            }
                        });
                        morv_rv.setAdapter(moreAdaptert);

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
